#!/usr/bin/env python
#-*- coding=utf-8 -*-

'''
这个脚本程序用于从www.qihuiwang.com中抓取企业发布的收售信息，
并将获得的信息保存到execl文件中

Author: Hevake Lee
E-mail: hevake_lcj@126.com

History:
    [2014-12-12 v1.0]   初步实现功能
'''

from QihuiwangPicker import *
from DataSaver import *

#---------------------------------------------------------------
def web_pick(path_filter, filename):
    picker = QihuiwangPicker()
    picker.set_filter(path_filter)
    picker.run()
    prod_list = picker.get_list_data()

    saver = DataSaver()
    saver.feed(prod_list)
    saver.save_as(filename)

#===============================================================
display_string = '''\
使用方法：%s 路径 保存文件
'''
from sys import argv

def display_usage():
    print(display_string % sys.argv[0])
    pass

if __name__ == '__main__':
    if len(argv) == 2:
        if argv[1] == 'test':
            test()
        else:
            web_pick('', argv[1])
    elif len(argv) == 3:
        web_pick(argv[1], argv[2])
    elif len(argv) == 1:
        #如果xlwt可用，则保存为xls文件格式
        if xlwt_enabled : 
            filename = 'data.xls'
        else:
            filename = 'data.csw'
        web_pick('', filename)
    else:
        display_usage()
